home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2c.lha / p4-1.2c / usc / usc.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  4KB  |  209 lines

  1. /*
  2.  * USC.C  (Source file for the Microsecond Clock package)
  3.  *
  4.  * Written by:  Arun Nanda    (07/17/91)
  5.  * Modified by R. Butler
  6.  */
  7.  
  8. #include "usc_sys.h"
  9.  
  10.  
  11. VOID usc_init()
  12. {
  13.  
  14. #if defined(MULTIMAX)
  15.  
  16.     usc_multimax_timer = timer_init();
  17.     usc_MD_rollover_val = (usc_time_t) ((1<<usc_MD_timer_size)-1);
  18.  
  19. #endif
  20.  
  21.  
  22. #if defined(SYMMETRY) || defined(SYMMETRY_PTX)
  23.  
  24.     unsigned long roll;
  25.  
  26.     usclk_init();
  27.  
  28.     roll = 1 << (usc_MD_timer_size-1);
  29.     usc_MD_rollover_val = (usc_time_t) (roll + roll - 1);
  30.  
  31. #endif
  32.  
  33.  
  34. #if defined(TC_2000) || defined(TC_2000_TCMP)
  35.  
  36.     unsigned long roll;
  37.  
  38.     roll = 1 << (usc_MD_timer_size-1);
  39.     usc_MD_rollover_val = (usc_time_t) (roll + roll - 1);
  40.  
  41. #endif
  42.  
  43.  
  44. #if defined(IPSC860)
  45.  
  46.     esize_t hwtime;
  47.     unsigned long ustime;
  48.  
  49.     hwtime.shigh = hwtime.slow = ~0x0;
  50.         hwtime.shigh = (hwtime.shigh & 0x7) << (sizeof(long)*8-3);
  51.         hwtime.slow = ((hwtime.slow >> 3) & ~(0x7 << (sizeof(long)*8-3)))
  52.                 | hwtime.shigh;
  53.         ustime = (unsigned long)hwtime.slow * 0.8;
  54.     usc_MD_rollover_val = (usc_time_t) ustime; 
  55.  
  56. #endif
  57.  
  58. #if defined(NCUBE)
  59.  
  60.         unsigned long roll;
  61.  
  62.         roll = 1 << (usc_MD_timer_size-1);
  63.         usc_MD_rollover_val = (usc_time_t) (roll + roll - 1);
  64.  
  65. #endif
  66.  
  67.  
  68. #if defined(FX2800)  ||  defined(FX2800_SWITCH)
  69.  
  70.     struct hrcval temptime;
  71.     unsigned long roll;
  72.  
  73.     hrcstamp(&temptime);
  74.     roll = 1 << ((sizeof(usc_time_t) * 8) - 1);
  75.     usc_MD_rollover_val = (usc_time_t) (roll + roll - 1);
  76.  
  77. #endif
  78.  
  79.  
  80. #if defined(SUN) || defined(HP) || defined(DEC5000) || \
  81.     defined(BALANCE) || \
  82.     defined(RS6000)  ||  defined(IBM3090) || \
  83.     defined(NEXT) || defined(TITAN) || defined(GP_1000) || \
  84.     defined(KSR)  || \
  85.     defined(SGI)  || defined(FX8)
  86.  
  87.     struct timeval tp;
  88.     struct timezone tzp;
  89.     unsigned long roll;
  90.  
  91.     gettimeofday(&tp,&tzp);
  92.  
  93.     roll = (usc_time_t) ((usc_time_t) 1 << ((sizeof(usc_time_t)*8)-1));
  94.     roll = roll + roll - 1;
  95.     usc_MD_rollover_val = (usc_time_t) (roll / 1000000);
  96.  
  97. #endif
  98.  
  99. }
  100.  
  101.  
  102.  
  103. usc_time_t usc_MD_clock()
  104. {
  105.  
  106. #if defined(TC_2000) || defined(TC_2000_TCMP)
  107.  
  108.     struct 
  109.     {
  110.     unsigned long hi;
  111.     unsigned long low;
  112.     } usclock;
  113.  
  114.     get64bitclock(&usclock);
  115.     return((usc_time_t)usclock.low);
  116.  
  117. #endif
  118.  
  119.  
  120. #if defined(IPSC860)
  121.  
  122.     esize_t hwtime;
  123.     unsigned long ustime;
  124.  
  125.     hwclock(&hwtime);
  126.         hwtime.shigh = (hwtime.shigh & 0x7) << (sizeof(long)*8-3);
  127.         hwtime.slow = ((hwtime.slow >> 3) & ~(0x7 << (sizeof(long)*8-3)))
  128.                 | hwtime.shigh;
  129.         ustime = (unsigned long)hwtime.slow * 0.8;
  130.     return( (usc_time_t) ustime);
  131.  
  132. #endif
  133.  
  134.  
  135. #if defined(NCUBE)
  136.    unsigned long ustime;
  137.    double amicclk();
  138.  
  139.     ustime = (unsigned long) amicclk();
  140.     /* printf("usc_MD_clock: returning %lu %u\n",ustime,ustime); */
  141.     return( (usc_time_t) ustime);
  142. #endif
  143.  
  144.  
  145. #if defined(FX2800)  ||  defined(FX2800_SWITCH)
  146.  
  147.     struct hrcval temptime;
  148.  
  149.     hrcstamp(&temptime);
  150.     return ((usc_time_t) (temptime.hv_low * 10));
  151.  
  152. #endif
  153.  
  154.  
  155. #if defined(SUN) || defined(HP) || \
  156.     defined(BALANCE) || \
  157.     defined(RS6000) || defined(IBM3090) || \
  158.     defined(NEXT) || defined(TITAN) || defined(TC1000) || \
  159.     defined(KSR)  || \
  160.     defined(SGI) || defined(FX8)
  161.  
  162.     unsigned long ustime;
  163.     struct timeval tp;
  164.     struct timezone tzp;
  165.  
  166.     gettimeofday(&tp,&tzp);
  167.     ustime = (unsigned long) tp.tv_sec;
  168.     ustime = ustime % usc_MD_rollover_val;
  169.     ustime = (ustime * 1000000) + (unsigned long) tp.tv_usec;
  170.  
  171.     return((usc_time_t) ustime);
  172.  
  173. #endif
  174.  
  175. #if defined(DEC5000)        
  176.        
  177. /*        
  178.  *  hack by pak@regent.e-technik.tu-muenchen.de:
  179.  *
  180.  *    clock resolution is 3906 us        
  181.  *    we can do about 120 calls in 3906 us == 32 us per call        
  182.  */        
  183.         unsigned long ustime;        
  184.         struct timeval tp;        
  185.         struct timezone tzp;        
  186.         static unsigned long last= 0;        
  187.         static unsigned long increment= 0;        
  188.        
  189.         gettimeofday(&tp,&tzp);        
  190.         ustime = (unsigned long) tp.tv_sec;        
  191.         ustime = ustime % usc_MD_rollover_val;        
  192.         ustime = (ustime * 1000000) + (unsigned long) tp.tv_usec;        
  193.        
  194.         if (last == ustime)
  195.         {
  196.           increment += 33L;
  197.         }
  198.         else
  199.         {
  200.           last = ustime;
  201.           increment = 0;
  202.         }
  203.  
  204.         return((usc_time_t) last + increment);
  205.  
  206. #endif
  207.  
  208. }
  209.